package com.base.andlang2.ui.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.base.andlang2.R
import com.base.andlang2.databinding.FragmentHomeBinding
import com.base.andlangcore.mvvm.AndLangFragment
import com.base.andlangrouter.RouteUrl
import com.base.andlangui.weight.ToastKt.toast

@Route(path = RouteUrl.APP_HOME_ONE)
class HomeFragment : AndLangFragment<FragmentHomeBinding,HomeViewModel>() {
    private lateinit var textView: TextView
    override fun getVB(inflater: LayoutInflater, container: ViewGroup?): FragmentHomeBinding {
        return FragmentHomeBinding.inflate(inflater, container, false)
    }

    override fun getVM(): HomeViewModel {
        return ViewModelProvider(this)[HomeViewModel::class.java]
    }

    override fun initView() {
        vb.apply {
            textView = textHome
            textView.setOnClickListener {
                ARouter.getInstance().build(RouteUrl.APP_SECOND_ACTIVITY).withString("key","首页跳转过来的")
                    .navigation()
            }
            btnOpen.setOnClickListener {
                toast("测试跳转")
            }
            btnOpenRn.setOnClickListener{
                ARouter.getInstance().build(RouteUrl.RN_MAIN_WEB)
                    .withString("bundleAssetName","index.android2.bundle")
                    .withString("jSMainModulePath","index")
                    .withString("moduleName","RNDemos")
                    .navigation()
            }
        }
        vm.apply {
            vm.text.observe(this@HomeFragment, Observer {
                textView.text = it
            })
        }
    }

    override fun initData() {
    }
}